package tests;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;

import pathfinding.GridCell;

public class GridCellTest {

	@Test
	public void testHashCode() {
		ArrayList<Integer> hashes = new ArrayList<Integer>();
		int total = 0;
		for (int i=-100; i <= 100; i++)
		{
			for (int j=-100; j <= 100; j++)
			{
				total++;
				GridCell c = new GridCell(i,j);
				Integer foo = new Integer(c.hashCode());
				if (hashes.contains(foo) == false)
				{
					hashes.add(foo);
				}
				else
				{
					//System.out.println("Collided:" + c);
				}
			}
		}
		
		System.out.println(hashes.size() + " unique keys out of " + total + ".");
	}

	@Test
	public void testClone() {
		GridCell a = new GridCell(1,-2);
		GridCell c = a.clone();
		
		assertTrue(a.equals(c));
	}

	@Test
	public void testEqualsObject() {
		GridCell a = new GridCell(1,-2);
		GridCell b = new GridCell(2,2);
		GridCell c = new GridCell(1,-2);
		
		assertTrue(a.equals(c));
		assertTrue(a.equals(a));
		assertTrue(a == a);
		assertTrue(a != c);
		assertTrue(a != b);
		
		assertTrue(a.equals(b) == false);
		assertTrue(a.equals(null) == false);
	}

	@Test
	public void testDirections() {
		GridCell a = new GridCell(13, -21);
		
		assertTrue(a.north().south().equals(a));
		assertTrue(a.east().west().equals(a));
		assertTrue(a.northeast().southwest().equals(a));
		assertTrue(a.northwest().southeast().equals(a));
		
		assertTrue(a.north().equals(a) == false);
		assertTrue(a.east().equals(a) == false);
		assertTrue(a.west().equals(a) == false);
		assertTrue(a.south().equals(a) == false);
		assertTrue(a.northeast().equals(a) == false);
		assertTrue(a.northwest().equals(a) == false);
		assertTrue(a.southeast().equals(a) == false);
		assertTrue(a.southwest().equals(a) == false);
		
		assertTrue(a.north().east().south().west().equals(a));
		assertTrue(a.south().northeast().west().equals(a));
	}

}
